import dateOptions from "@/utils/date"; //引入date的渲染
import {findTable,searchAllGoods} from "@/api/totalMaket"; //分类信息


let brand = {
    name: "index",
    data() {
        return {
            searchMarketData: {
                currentPage: 1,//当前页
                pageSize: 5,//每页显示条数
            },
            total:0,
            dateOptions,
            tableData:[],
            typeIdList:[],
            brandIdList:[],
            productColorIdList:[],



        }
    },
    created() {//
        //查询
        this.searchPage();
        //所有下拉列表赋值
        this.findAllGoods();

    },
    methods: {
        async searchPage() {
            //执行查询
            let response = await findTable(this.searchMarketData);
            console.log(response);
            this.total = response.total;//总行数复制
            this.tableData = response.data;//数据信息赋值
        },
        //点击下一页 发生改变
        async currentPageChange(page) {
            console.log(page);
            this.searchMarketData.currentPage = page;//当前页赋值
            console.log(this.searchMarketData.currentPage);
            this.searchPage();//刷新页面
        },
        findTotalMarketBylike(){
            this.searchPage();
        },
        async findAllGoods(){
            let response = await searchAllGoods();
            //所有的订单信息
            // console.log(response);
            let arr=[];
            //赋值商品分类
            for (let i = 0; i <response.length ; i++) {
                arr[i] = response[i].typeId;
            }
            //去掉支付方式中的重复元素
            for (let i = 0; i <arr.length; i++) {
                if(this.typeIdList.indexOf(arr[i]) === -1){
                    this.typeIdList.push(arr[i]);
                }
            }
            //赋值商品品牌
            for (let i = 0; i <response.length ; i++) {
                arr[i] = response[i].brandId;
            }
            //去掉支付方式中的重复元素
            for (let i = 0; i <arr.length; i++) {
                if(this.brandIdList.indexOf(arr[i]) === -1){
                    this.brandIdList.push(arr[i]);
                }
            }
            //赋值商品商品颜色
            for (let i = 0; i <response.length ; i++) {
                arr[i] = response[i].productColorId;
            }
            //去掉支付方式中的重复元素
            for (let i = 0; i <arr.length; i++) {
                if(this.productColorIdList.indexOf(arr[i]) === -1){
                    this.productColorIdList.push(arr[i]);
                }
            }
        },
        resetForm(){
            this.searchMarketData.currentPage =1;
            this.searchMarketData.pageSize =5;
            this.searchMarketData.goodsName='';
            this.searchMarketData.typeNubmer = '';
            this.searchMarketData.brandId = '';
            this.searchMarketData.productColorId = '';
            // 重置后重新加载页面
            this.searchPage();
        },

    }
};
export default brand;